package com.sport.facilities.booking.system.ui;

import java.util.List;

import com.sport.facilities.booking.system.R;
import com.sport.facilities.booking.system.model.Friend;

import android.app.Activity;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

public class FriendListAdapter extends ArrayAdapter<Friend> {

	protected static final String LOG_TAG = FriendListAdapter.class.getSimpleName();
	
	private List<Friend> items;
	private int layoutResourceId;
	private Context context;

	public FriendListAdapter(Context context, int layoutResourceId, List<Friend> items) {
		super(context, layoutResourceId, items);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		FriendHolder holder = null;

		LayoutInflater inflater = ((Activity) context).getLayoutInflater();
		row = inflater.inflate(layoutResourceId, parent, false);

		holder = new FriendHolder();
		holder.Friend = items.get(position);
		


		holder.name = (TextView)row.findViewById(R.id.contact_name);
		holder.name.setKeyListener(null);
				
		holder.email = (TextView)row.findViewById(R.id.contact_email);
		holder.email.setKeyListener(null);
		
		holder.phone = (TextView)row.findViewById(R.id.contact_phone);
		holder.phone.setKeyListener(null);
		
		holder.id = (TextView)row.findViewById(R.id.contact_id);
		holder.id.setKeyListener(null);
		//setValueTextListeners(holder);

		row.setTag(holder);

		setupItem(holder);
		return row;
	}

	
	private void setupItem(FriendHolder holder) {
		holder.name.setText(holder.Friend.getName());
		holder.email.setText(String.valueOf(holder.Friend.getEmail()));
		holder.phone.setText(String.valueOf(holder.Friend.getPhone()));
		holder.id.setText(String.valueOf(holder.Friend.getId()));
	}

	public static class FriendHolder {
		public Friend Friend;		
		TextView name;
		TextView email;
		TextView phone;
		TextView id;

	}
	
	
}
